//compute kid marriage probabilities -- HS
use "$temp/acs_master", clear
keep if year>=2008 & year<=2012 //limit year range
keep if age>=36 & age<=54 //limit age range
keep if relate == 1 //household heads
gen incwage_orig = incwage


preserve

import delimited "$dir/Model/utilities/state_chars_2010.csv", clear
ren v1 statefips
ren v2 skill_price_2010
ren v3 skill_price_coll_2010
keep state skill*
tempfile skill_prices
save `skill_prices'
restore

ren statefip statefips
//merge m:1 statefips using "$temp/skill_prices_all", keep(match) nogen
merge m:1 statefips using `skill_prices', keep(match) nogen

//adjust skill prices for race
replace skill_price_2010 = exp(log(skill_price_2010) - 0.145) if racetype == 2
replace skill_price_2010 = exp(log(skill_price_2010) - 0.087) if racetype == 3

replace skill_price_coll_2010 = exp(log(skill_price_coll_2010) - 0.145) if racetype == 2
replace skill_price_coll_2010 = exp(log(skill_price_coll_2010) - 0.087) if racetype == 3

replace incwage = incwage/skill_price_2010 if !coll //normalize by skill prices
replace incwage = incwage/skill_price_coll_2010 if coll //normalize by skill prices
local norm = 47961
replace incwage = incwage/`norm' //normalize by mean PSID earnings
replace incwage_orig = incwage_orig/`norm' //normalize by mean PSID earnings

gen move = (statefips!=bpl)

//after these normalizations, incwage =human capital after hours adjustment
ren incwage hc
su hc [fw=perwt], d //fairly comparable

//replace hc = `r(p99)' if hc>`r(p99)'
drop if hc>6
replace hc = hc * (2080/hours) //hours normalization

su hc [fw=perwt], d //now VERY comparable -- looks good!
gen hc2 = hc^2
gen hc3 = hc^3
save "$temp/acs_master_kid_sample", replace //for later use

//re-open and get to work
use "$temp/acs_master_kid_sample", clear

//gen mig = (statefip!=bpl)

//recode marriage
gen married=0
replace married = 1 if marst == 1 | marst == 2
gen mig = (statefips!=bpl)
reg married hc* mig i.statefips i.bpl [fw=perwt], robust


//get shifters for blacks/hispanics
probit married hc* mig i.bpl ib1.racetype if hc<3.0 & !coll [fw = perwt], robust 
probit married hc* mig i.bpl ib1.racetype if hc<3.0 & coll [fw = perwt], robust 


preserve
keep if !coll
//marriage polynomials for kids, based on birth place
levelsof bpl, clean local(fips)
foreach fip in `fips'{
	noi di "`fip'"
	qui probit married hc* mig if bpl == `fip' & hc<3.0 [fw = perwt], robust
	local cons`fip' = _b[_cons]
	local hc_`fip' = _b[hc]
	local hc2_`fip' = _b[hc2]
	local hc3_`fip' = _b[hc3]
	local mig_`fip' = _b[mig]
	
	qui su married if hc>3.0 & bpl == `fip' [fw=perwt]
	local cap_`fip' = `r(mean)'
}

//turn into data
clear
set obs 50
gen fips = .
gen cons = .
gen b1 = .
gen b2 = .
gen b3 = .
gen cap = .
gen mig = .
local counter = 0
foreach fip in `fips'{
	local counter `++counter'
	replace fip = `fip' in `counter'
	replace cons = `cons`fip'' in `counter'
	replace b1 = `hc_`fip'' in `counter'
	replace b2 = `hc2_`fip'' in `counter'
	replace b3 = `hc3_`fip'' in `counter'
	replace cap = `cap_`fip'' in `counter'
	replace mig = `mig_`fip'' in `counter'
}

compress
export delimited "$dir/Model/utilities/kid_marriage_probs_noncoll.csv", replace novarn
restore

keep if coll
//marriage polynomials for kids, based on birth place
levelsof bpl, clean local(fips)
foreach fip in `fips'{
	noi di "`fip'"
	qui probit married hc* mig if bpl == `fip' & hc<3.0 [fw = perwt], robust
	local cons`fip' = _b[_cons]
	local hc_`fip' = _b[hc]
	local hc2_`fip' = _b[hc2]
	local hc3_`fip' = _b[hc3]
	local mig_`fip' = _b[mig]

	
	qui su married if hc>3.0 & bpl == `fip' [fw=perwt]
	local cap_`fip' = `r(mean)'
}

//turn into data
clear
set obs 50
gen fips = .
gen cons = .
gen b1 = .
gen b2 = .
gen b3 = .
gen cap = .
gen mig = .
local counter = 0
foreach fip in `fips'{
	local counter `++counter'
	replace fip = `fip' in `counter'
	replace cons = `cons`fip'' in `counter'
	replace b1 = `hc_`fip'' in `counter'
	replace b2 = `hc2_`fip'' in `counter'
	replace b3 = `hc3_`fip'' in `counter'
	replace cap = `cap_`fip'' in `counter'
	replace mig = `mig_`fip'' in `counter'	
}

compress
export delimited "$dir/Model/utilities/kid_marriage_probs_coll.csv", replace novarn

//end of do-file